class @AdminResponseEditView extends CustomView

    el: $('#content')
        
    initialize: ->
        super
        @model.bind("change", @render)
        @model.fetch()

    render: ->
        model = @model
        el = @$el

        @GetTemplate(SiteMap.Admin.Responses.EditTemplate, (compiledTemplate) =>
            el.html(compiledTemplate(@model.toJSON()))
                
            $("#UserId").combobox({
                source: SiteMap.Admin.Shared.GetUsers
                minLength: 2 
                isDynamic:true
                valueSource: SiteMap.Admin.Shared.GetUserById+"?userId="+model.get("UserId")

            })
            $('#BookId').combobox(
                source: SiteMap.Admin.Shared.GetBooks
                minLength: 2 
                isDynamic:true
                valueSource: SiteMap.Admin.Shared.GetBookById+"?bookId="+model.get("BookId")
            )
            $("#DateOfPublish").datepicker()
        )

    events:
        "click .buttons>button.save": "save"
        "click .buttons>button.cancel": "cancel"

    save: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.WriteMessage('Saving comment.')

        data = $(@el).find("form.general").serialize()

        $.post(SiteMap.Admin.Responses.Edit + "?responseId=" + @model.get("ResponseId"), data, (response)=>
            if (response.SuccessMessage != null && response.SuccessMessage.length > 0)
                Messages.WriteSuccessMessage(response.SuccessMessage)
                @Navigate(SiteMap.Admin.Responses.Listing, true)
            else
                Messages.WriteErrors(response.Errors)
                Loading.Stop()
        )

    cancel: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.Clear()
        @Navigate(SiteMap.Admin.Responses.Listing, true)